<template>
  <el-dialog :append-to-body="true" :visible.sync="dialog" title="绑定银行卡" width="600px">
    <el-form ref="form" :model="form" :rules="rules" size="small" label-width="120px">
      <el-form-item label="姓名/所属平台:" prop="owner_name">
        <el-input v-model="form.owner_name" style="width: 370px;"/>
      </el-form-item>
      <el-form-item label="银行卡:" prop="card_id">
        <el-input v-model="form.card_id" style="width: 370px;"/>
      </el-form-item>
      <el-form-item label="开户银行:" prop="bank_type">
        <el-input v-model="form.bank_type" style="width: 370px;"/>
      </el-form-item>
      <el-form-item label="开户支行:" prop="bank_name">
        <el-input v-model="form.bank_name" style="width: 370px;"/>
      </el-form-item>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button type="text" @click="cancel">取消</el-button>
      <el-button :loading="loading" type="primary" @click="doSubmit">确认</el-button>
    </div>
  </el-dialog>
</template>

<script>
import { bindingCard } from '@/api/mall/workers'
export default {
  components: { },
  data() {
    return {
      loading: false, dialog: false,
      form: {
        owner_name: '',
        card_id: '',
        bank_type: '',
        bank_name: '',
        user_ids: []
      },
      rules: {
        owner_name: [
          { required: true, message: '请输入姓名/所属平台', trigger: 'blur' }
        ],
        card_id: [
          { required: true, message: '请输入银行卡信息', trigger: 'blur' }
        ],
        bank_type: [
          { required: true, message: '请输入开户银行信息', trigger: 'blur' }
        ],
        bank_name: [
          { required: true, message: '请输入开户支行信息', trigger: 'blur' }
        ]
      }
    }
  },
  methods: {
    cancel() {
      this.resetForm()
    },
    doSubmit() {
      // 表单验证
      this.$refs['form'].validate((valid) => {
        // 通过
        if (valid) {
          this.doAdd()
        }
      })
    },
    doAdd() {
      bindingCard(this.form).then(() => {
        this.resetForm()
        this.$notify({
          title: '添加成功',
          type: 'success',
          duration: 2500
        })
        this.loading = false
        this.$parent.init()
      }).catch(() => {
        this.loading = false
      })
    },
    resetForm() {
      this.dialog = false
      this.$refs['form'].resetFields()
      this.form = {
        commodity_id: '',
        level: 1,
        nick: '',
        icon_url: '',
        content: '',
        urls: []
      }
    }
  }
}
</script>

<style rel="stylesheet/scss" lang="scss" scoped>
  /deep/ .el-input-number .el-input__inner {
    text-align: left;
  }

</style>
